package com.ultrapower.request;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;

import com.ultrapower.bean.AgentInfoBean;
import com.ultrapower.hbase.HbaseUtil;
import com.ultrapower.mapper.AgentInfoMapper;
import com.ultrapower.util.HBaseTables;

/**
 * 
 * @author wangy
 */
public class AgentInfoTable extends BaseRequest {
	public static void main(String[] args) {
		AgentInfoTable agentInfo = new AgentInfoTable();
		agentInfo.execute();
	}

	@Override
	public void execute() {

		TableName applicationIndexTableName = HbaseUtil.getTableName(HBaseTables.AGENTINFO_STR);
		Set<String> distinctApp=new TreeSet<>();
		this.getHbaseTemplate().find(applicationIndexTableName, createScan(), (ResultScanner scanner) -> {
			AgentInfoMapper map = new AgentInfoMapper();
			scanner.forEach(r -> {
				try {
					AgentInfoBean info = map.mapRow(r, 0);
					System.out.println(info);
					distinctApp.add(info.getApplicationName()+"##"+info.getAgentId()+"##"+info.getServiceTypeCode());
				} catch (Exception e) {
					e.printStackTrace();
				}
			});
			return null;
		});
		System.out.println("************简单数据***********");
		distinctApp.forEach(a->{
			System.out.println(a);
		});
	}

	@Override
	protected Scan createScan() {
		Scan scan = new Scan();
		scan.setCaching(30);
		return scan;
	}
}
